package com.zhp.config;

import com.zhp.aspect.IdempotentAspect;
import com.zhp.helper.RedisHelper;
import com.zhp.keyresolver.IdempotentKeyResolver;
import com.zhp.keyresolver.impl.DefaultIdempotentKeyResolver;
import com.zhp.keyresolver.impl.ExpressionIdempotentKeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zhanghp
 * @since 2024/5/27 13:56
 */
@SuppressWarnings("all")
@Component
public class IdempotentConfig {

    // ==========  幂等 切面类 ==========
    @Bean
    public IdempotentAspect idempotentAspect(List<IdempotentKeyResolver> keyResolvers, RedisHelper redisHelper) {
        return new IdempotentAspect(keyResolvers, redisHelper);
    }

    // ========== 各种 IdempotentKeyResolver Bean ==========

    @Bean
    public DefaultIdempotentKeyResolver defaultIdempotentKeyResolver() {
        return new DefaultIdempotentKeyResolver();
    }

    @Bean
    public ExpressionIdempotentKeyResolver expressionIdempotentKeyResolver() {
        return new ExpressionIdempotentKeyResolver();
    }
}
